var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({
    data: {
        ebatch: null, //考试批次信息
        stuInfo: null, //考生信息
        time: null, //倒计时
        countDown: null,
        agree: false,
        showModal: false, //考试须知
        enter: false,
        loginTxext: '开始考试'
    },
    onLoad: function (options) {

    },
    onShow: function () {
        var _this = this
        //    _this.setData({
        //     ebatch:wx.getStorageSync('ebatchInfo'),
        //      stuInfo:wx.getStorageSync('stuInfo'),
        //      nowDate:wx.getStorageSync('nowDate')
        //  })

        wx.request({
            url: siteinfo.selServerNowDate,
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            method: "POST",
            data: {},
            success: function (result) {
                let oldObj = wx.getStorageSync('ebatchInfo')
                // 如果字符串包含“师资”，那么就取师资后面的字符串，否则直接返回
                if (!oldObj.name.split('师资')[0]) {

                    oldObj.name = oldObj.name.split('师资')[1]
                }

                wx.setStorageSync('nowDate', new Date(result.data))
                _this.setData({
                    // ebatch: wx.getStorageSync('ebatchInfo'),
                    ebatch: oldObj,
                    stuInfo: wx.getStorageSync('stuInfo')
                })
                util.calculateTime(_this, wx.getStorageSync('ebatchInfo').startTime)
            }
        })
    },
    //倒计时
    sumitPaper: function () {
        var _this = this;
        _this.setData({
            enter: true
        })
        // var i = setInterval(function() {
        //   if(_this.data.countDown=='考试已开始' || _this.data.time<=0){
        //     _this.setData({
        //       countDown:'考试已开始',
        //       enter:true
        //     })
        //     app.showError('考试已开始')
        //     clearInterval(i)
        //   }else{
        //     var t=_this.data.time-1
        //     var h=util.addZero(parseInt(t/3600%24))
        //     var m=util.addZero(parseInt(t/60%60))
        //     var s=util.addZero(parseInt(t%60))
        //     _this.setData({
        //       time:t,
        //       countDown:'考试倒计时 '+h+'小时'+m+'分钟'+s+'秒'
        //     })
        //   }
        // }, 1000)
    },
    //勾选同意
    checkboxChange(e) {
        if (this.data.agree == false) {
            this.setData({
                agree: true
            })
        } else {
            this.setData({
                agree: false
            })
        }
    },
    lookView: function () {
        this.setData({
            showModal: true
        })
    },
    closeView: function () {
        this.setData({
            showModal: false
        })
    },
    //登录
    login: function (e) {
        var _this = this;
        if (_this.data.agree) {
            wx.request({
                url: siteinfo.changeState,
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                method: "POST",
                data: {
                    id: wx.getStorageSync('stuInfo').stuSignId
                },
                success: function (result) {
                    wx.navigateTo({
                        url: '/pages/examinationNonStu/examinationNonStu',
                    })
                }
            })
        } else {
            app.showError('请勾选已同意')
        }
    },
    /**
     * 跳转回原页面
     */
    navigateBack: function () {
        // wx.navigateBack();
        wx.navigateBack({
            delta: 2
        })

    },
})